import cv2 as cv
import numpy as np

blue = np.uint8([[[255, 0, 0]]])
hsv_blue = cv.cvtColor(blue, cv.COLOR_BGR2HSV)
print(hsv_blue)
image = cv.imread('cap.jpg')
#  将图像从BGR转换到HSV颜色空间
hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
# 定义HSV中蓝色的下界和上界
lower_blue = np.array([110, 60, 60])
upper_blue = np.array([130, 255, 255])
# [lower_blue,upper_blue]内的像素为255，其他为0
mask = cv.inRange(hsv, lower_blue, upper_blue)
# 对mask和image按位和  提取深蓝色瓶盖
res = cv.bitwise_and(image, image, mask=mask)
cv.imshow('image', image)
cv.imshow('mask', mask)
cv.imshow('res', res)
k = cv.waitKey(0)
cv.destroyAllWindows()